<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<t:base type="jquery,easyui,tools,DatePicker"></t:base>

<div id="main_todo_list" class="easyui-layout" fit="true">
    <div region="center" style="padding:0px;border:0px">
        <t:datagrid name="todoWoList" title="待办工单列表"
                    actionUrl="woController.do?todoWoGrid"
                    treegrid="false" idField="id" pagination="true" sortOrder="desc" sortName="workOrder.createDatetime" onLoadSuccess="" pageSize="15">
            <t:dgCol title="待办编号" field="id" hidden="true" ></t:dgCol>
            <t:dgCol title="工单来源" field="workOrder.woSrcDesc" width="80" ></t:dgCol>
            <t:dgCol title="工单编号" field="workOrder.wo95598Id" width="100" ></t:dgCol>	        
	        <t:dgCol title="联系人 " field="workOrder.contactMan" width="100" query="true"></t:dgCol>
	        <t:dgCol title="联系电话 " field="workOrder.contactPhone" width="100" query="true"></t:dgCol>
	        <t:dgCol title="处理人员" field="workOrder.doUsername" width="60"  query="true"></t:dgCol>
	        <t:dgCol title="创建时间 " field="workOrder.createDatetime"  width="100" formatter="yyyy.MM.dd hh:mm:ss"></t:dgCol>
	        <t:dgCol title="已读状态" field="isRead" width="60" ></t:dgCol>
	        <t:dgCol title="common.operation" field="opt" width="80"></t:dgCol>
            <t:dgFunOpt funname="processWoDetail(id)" title="处理工单"></t:dgFunOpt>
            <t:dgFunOpt funname="PrintWoURL(id)" title="打印"></t:dgFunOpt> 
        </t:datagrid>
    </div>
</div>

<div id="dlg">
        Content
</div>

<script language="javascript" src="plug-in/lodop/LodopFuncs.js"></script>
<script type="text/javascript">
    var LODOP; //声明为全局变量 
	$(function() {
	
	    $('#todoWoList').datagrid({  
		   onDblClickRow: function (rowIndex, rowData) {  
			   processWoDetail(rowData.id);
		   }
	   });
	    
	   //定时刷新每15分钟
	   setInterval(loadTodoWo, 15*60*1000);  	    
	});
    
     
    
    function loadTodoWo(){
    	 
   		 $('#todoWoList').datagrid('reload');
    }

   function processWoDetail(id){
	   $.dialog({  
		    id: 'LHG1976D',  
		    title: "处理工单",  
		    max: true,  
		    min: true,  
		    zIndex: getzIndex(),
		    drag: true,  
		    resize: true, 
			width:1210,
			height: 630, 
		    content: 'url:'+"woController.do?todoWoTabs&todo_id=" + id,  
		    opacity : 0.3,
			cache:false, 
		    cancelVal: '关闭',
		    cancel: true,
		    button : [ {  
		        name : "提交",  
		        focus : true,  
		        callback : function() {  
		            iframe = this.iframe.contentWindow;  
		            var woOpinion = $('#woOpinion', iframe.tabFrame.document).val();  
		            if(woOpinion.trim()==''){
		           	    showAlert('请填写处理意见！');
		             	return false;
		            } 
		            
		            var tipMsg = '';
		            var woState = $('#woState', iframe.tabFrame.document).val(); 
		            var woStateTxt =  $('#woState', iframe.tabFrame.document).find("option:selected").text();		            
		            var zOrgIds = $('#zOrgIds', iframe.tabFrame.document).val();  
		            var zDepartname = $('#zDepartname', iframe.tabFrame.document).val();  
		            
		            $('#saveState', iframe.tabFrame.document).val('1');  
		            
		            if(woState=='S03'){
		    	        if(zOrgIds.trim()==''){
		    	        	showAlert('请选择主办部门！');
		    	        	return false;
		    	        } 
		    	        tipMsg = '确认【'+woStateTxt+'】到【'+zDepartname+'】吗?';
		            }else{
		            	tipMsg = '确认【'+woStateTxt+'】吗?';
		            }
		        	confirmMsg(tipMsg,iframe,this);
		            return false;
		            
		            
		        } 
		    },{  
		        name : "保存",  
		        focus : false,  
		        callback : function() {  
		        	iframe = this.iframe.contentWindow;  
		        	 //保存状态
		            $('#saveState', iframe.tabFrame.document).val('0'); 
		            doTodoForm(iframe);
					 
		        }
		    }] 
		});
   }
   
   function doTodoForm(frame) {
	
		$('#myform', frame.tabFrame.document).form('submit', {
			success : function(data) {
				var d = $.parseJSON(data);
				if (d.success) {
					var msg = d.msg;
					tip(msg);
					reloadTable();
				};
			},
			error:function(data){
				var d = $.parseJSON(data);
				if (d.success) {
					var msg = d.msg;
					tip(msg);
				};
			}
			
		});
	}
   
   function showAlert(msg){
	   $.dialog({  
		    id: 'LHG1976C',  
		    title: "操作提示",  
		    max: false,  
		    min: false,  
		    zIndex: getzIndex(),
		    drag: false,  
		    resize: false, 
			width:200,
			height: 80, 
		    content: msg,  
		    opacity : 0.3,
			cache:false, 
		    cancelVal: '关闭',
		    cancel: true
		});
   }

   function confirmMsg(msg,frame,dlg){
	   $.dialog({  
		    id: 'LHG1978C',  
		    title: "操作提示",  
		    max: false,  
		    min: false,  
		    zIndex: getzIndex(),
		    drag: false,  
		    resize: false, 
			width:200,
			height: 80, 
		    content: msg,  
		    opacity : 0.3,
			cache:false, 
		    cancelVal: '关闭',
		    cancel: true,
		    button : [ {  
		        name : "确定",  
		        focus : true,  
		        callback : function() {  
		        	doTodoForm(frame); 
		        	dlg.close();
		        }  
		    }] 
		});
   }
   
	function PrintWoURL(id){
 		LODOP=getLodop();  
		LODOP.PRINT_INIT("工单打印");
		//LODOP.SET_PRINT_PAGESIZE(1,"95%","95%",0,"A4");
		LODOP.ADD_PRINT_URL(20,20,"90%","90%","woController.do?woPrint&todo_id=" + id);
		//LODOP.SET_PREVIEW_WINDOW(2,0,0,0,0,""); //按适宽模式显示

	//	LODOP.SET_PRINT_STYLEA(0,"HOrient",3);
	//	LODOP.SET_PRINT_STYLEA(0,"VOrient",3);
//		LODOP.SET_SHOW_MODE("MESSAGE_GETING_URL",""); //该语句隐藏进度条或修改提示信息
//		LODOP.SET_SHOW_MODE("MESSAGE_PARSING_URL","");//该语句隐藏进度条或修改提示信息
		LODOP.PREVIEW();  			
	};
	
</script>